﻿using System.Windows;
using System.Windows.Media;
using System.Windows.Data;
using System.Windows.Shapes;

namespace SuperFrame.Charts
{
    public class LegendItem : DependencyObject
    {
        public LegendItem()
        {
        }

        public Shape Shape
        {
            get { return (Shape)GetValue(ShapeProperty); }
            set { SetValue(ShapeProperty, value); }
        }
        public static readonly DependencyProperty ShapeProperty = DependencyProperty.Register("Shape", typeof(Shape), typeof(LegendItem), new PropertyMetadata(null));


        public BaseSeries Series
        {
            get { return (BaseSeries)GetValue(SeriesProperty); }
            set { SetValue(SeriesProperty, value); }
        }
        public static readonly DependencyProperty SeriesProperty = DependencyProperty.Register("Series", typeof(BaseSeries), typeof(LegendItem), new PropertyMetadata(null, OnSeriesChanged));
        private static void OnSeriesChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
        {
            (sender as LegendItem).SeriesChanged(args);
        }
        internal void SeriesChanged(DependencyPropertyChangedEventArgs args)
        {
            if (!(Series is SeriesColumn))
            {
                Binding binding = new Binding();
                binding.Source = Series;
                if (Series is BaseFillSeries)
                    binding.Path = new PropertyPath("Fill");
                else
                    binding.Path = new PropertyPath("Stroke");
                BindingOperations.SetBinding(this, LegendItem.IconColorProperty, binding);

                BindingOperations.SetBinding(this, LegendItem.LabelProperty, new Binding("Label") { Source = Series });
            }
        }

        public Brush IconColor
        {
            get { return (Brush)GetValue(IconColorProperty); }
            set { SetValue(IconColorProperty, value); }
        }
        public static readonly DependencyProperty IconColorProperty = DependencyProperty.Register("IconColor", typeof(Brush), typeof(LegendItem), new PropertyMetadata(null));


        public object Label
        {
            get { return (object)GetValue(LabelProperty); }
            set { SetValue(LabelProperty, value); }
        }
        public static readonly DependencyProperty LabelProperty = DependencyProperty.Register("Label", typeof(object), typeof(LegendItem), new PropertyMetadata(null));


        public bool ShowIcon
        {
            get { return (bool)GetValue(ShowIconProperty); }
            set { SetValue(ShowIconProperty, value); }
        }
        public static readonly DependencyProperty ShowIconProperty = DependencyProperty.Register("ShowIcon", typeof(bool), typeof(LegendItem), new PropertyMetadata(null));


    }
}
